﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PyramidShadow
{
    class VictoryScreen
    {
        private String globalMessage;
        private String specialMessage;
        private bool hasSpecMesg;
        private Texture2D background;
        private Vector2 bg_position,
                        spcMsg_pos,
                        gloMsg_pos,
                        conti_pos;
        private Game1 game;
        private SpriteFont font;

        private const float scaleFactor = 2.5f;
        private const Keys continueButton = Keys.Enter;
        private const String continueMsg = "Press " + continueButton + " to Continue.";

        public VictoryScreen(String globalMessage, Game1 game)
        {
            this.globalMessage = globalMessage;
            hasSpecMesg = false;
            this.game = game;

            // tbd------------------------------------------------
            background = game.Content.Load<Texture2D>(@"");
      
            bg_position = new Vector2(
                    (game.Window.ClientBounds.Width / 2) - (background.Width / 2),
                    (game.Window.ClientBounds.Height / 2) - (background.Height / 2));

            font = game.Content.Load<SpriteFont>("fonts/SpriteFont1");

            //Calculate position for gloablMessage
            float x, y;
            x = font.Spacing * globalMessage.Length;
            x *= scaleFactor;
            x /= 2;
            x = bg_position.X - x;
            y = 2 * font.LineSpacing * scaleFactor;
            y = game.Window.ClientBounds.Height - y;
            gloMsg_pos = new Vector2(x, y);

            //Calculate position for continue Message
            x = font.Spacing * continueMsg.Length;
            x /= 2;
            x = bg_position.X - x;
            y = 2 * font.LineSpacing;
            conti_pos = new Vector2(x, y);
        }

        public void setSpecMessage(String msg)
        {
            hasSpecMesg = true;
            specialMessage = msg;

            //Calculate position for specialMessage
            float x, y;
            x = font.Spacing * specialMessage.Length;
            x /= 2;
            x = bg_position.X - x;
            y = 4 * font.LineSpacing;
            y = spcMsg_pos.Y - y;
            spcMsg_pos = new Vector2(x, y);
        }

        public void Update(GameTime gameTime)
        {
            KeyboardState currentKeyboarsState = Keyboard.GetState();

            if(currentKeyboarsState.IsKeyDown(continueButton))
                game.loadNextLevel();
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(background, bg_position, Color.White);
            spriteBatch.DrawString(font, globalMessage, gloMsg_pos, Color.White);
            if(hasSpecMesg)
                spriteBatch.DrawString(font, specialMessage, spcMsg_pos, Color.White);
            spriteBatch.DrawString(font, continueMsg, conti_pos, Color.White);
        }
    }
}
